package com.erplan.swt.app.gx.dialogs;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import com.erplan.swt.app.gx.Gx;

public class GxAbout {

	public Shell createAboutDialog(Shell shell, Display display){
		final Image iconImage = new Image(display, Gx.class.getResourceAsStream("images/icon.gif"));

		final Shell aboutDialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		aboutDialog.setSize(300, 150);
		aboutDialog.setText("About " + Gx.toolTextSmall);

		Label lblImage = new Label(aboutDialog, SWT.NONE);
		lblImage.setImage(iconImage);
		lblImage.setBounds(10, 10, 40, 35); //len1,ht1,len2,ht2

		//new Label (shell, SWT.SEPARATOR | SWT.HORIZONTAL);
		Label lblAboutDialog = new Label(aboutDialog, SWT.WRAP);
		lblAboutDialog.setBounds(55, 10, 270, 80); //len1,ht1,len2,ht2
		lblAboutDialog.setText(Gx.toolText + " " + Gx.toolVersion + "\n\n" +
				"(c) Copyright 2008 Gaurav. All rights reserved.");

//	    Font initialFont = lblAboutDialog.getFont();
//	    FontData[] oldfontData = initialFont.getFontData();
//	    for (int i = 0; i < oldfontData.length; i++) {
//	    	System.out.println(oldfontData[i] + " ### " + oldfontData[i].getHeight());
//	    	fontData[i].setHeight(8);
//	    }

		FontData fontData[] = new FontData[]{new FontData("AvantGarde LT Medium", 7, SWT.BOLD)};
	    Font newFont = new Font(display, fontData);
	    lblAboutDialog.setFont(newFont);

	    final Button btnAboutDialogOK = new Button (aboutDialog, SWT.PUSH | SWT.BUTTON1);
		btnAboutDialogOK.setText("OK");
		btnAboutDialogOK.setBounds(235, 90, 50, 25);
		Listener okButtonListener = new Listener () {
			public void handleEvent (Event event) {
				aboutDialog.close();
			}
		};
		btnAboutDialogOK.addListener (SWT.Selection, okButtonListener);

		Rectangle aboutDialogRect = aboutDialog.getBounds();
		Rectangle displayRect = display.getBounds();
	    int aboutDialogX = (displayRect.width - aboutDialogRect.width) / 2;
	    int aboutDialogY = (displayRect.height - aboutDialogRect.height) / 2;
	    aboutDialog.setLocation(aboutDialogX, aboutDialogY);

        return aboutDialog;
	}
//
//	public static void main(String args[]){
//		Display display = new Display();
//		Shell shell = new Shell(display, SWT.MIN | SWT.CLOSE | SWT.RESIZE);
//		shell.setSize(700, 600);
//		shell.open();
//
//		P5About about = new P5About();
//		Shell aboutShell = about.createAboutDialog(shell, display);
//		aboutShell.open();
//
//		while (!aboutShell.isDisposed()) {
//			if (!display.readAndDispatch ()) display.sleep ();
//		}
//		display.dispose();
//	}
}
